home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / usr (gcc 1.37 libs) / mac / pipe.c < prev    next >
C/C++ Source or Header  |  1993-12-08  |  1KB  |  53 lines

  1. #include <OSUtils.h>
  2. #include <Events.h>
  3. #include <EPPC.h>
  4. #include <Processes.h>
  5. #include <stdio.h>
  6. #include <fcntl.h>
  7. #include "crtlocal.h"
  8.  
  9. static OSErr waitforcompletion(volatile OSErr *err)
  10.     {
  11.     while (*err == 1)
  12.             {
  13.             ProcessSerialNumber mysn = {0, 0};
  14.             EventRecord event;
  15.             mysn.lowLongOfPSN = kSystemProcess;
  16.             SetFrontProcess(&mysn);
  17.             WaitNextEvent(0x0, &event, 60, NULL);
  18.             mysn.lowLongOfPSN = kCurrentProcess;
  19.             SetFrontProcess(&mysn);
  20.             }
  21.     return *err;
  22.     }
  23.  
  24. long readpipe(int fd, char *readbuffer, long size)
  25.     {
  26.     OSErr err;
  27.     PPCReadPBRec thedata;
  28.     thedata.sessRefNum = crt_fd_tab[fd].fd;
  29.     thedata.ioCompletion = 0;
  30.     thedata.bufferLength = size;
  31.     thedata.bufferPtr = readbuffer;
  32.     err = PPCReadAsync(&thedata);
  33.     err = waitforcompletion(&thedata.ioResult);
  34.     return thedata.actualLength;
  35.     }
  36.  
  37. long writepipe(int fd, char *writebuffer, long size)
  38.     {
  39.     OSErr err;
  40.     PPCWritePBRec thedata;
  41.     thedata.sessRefNum = crt_fd_tab[fd].fd;
  42.     thedata.ioCompletion = 0;
  43.     thedata.bufferLength = size;
  44.     thedata.bufferPtr = writebuffer;
  45.     thedata.more = 0;
  46.     thedata.userData = 0;
  47.     thedata.blockCreator = '????';
  48.     thedata.blockType = '????';
  49.     err = PPCWriteAsync(&thedata);
  50.     err = waitforcompletion(&thedata.ioResult);
  51.     return thedata.actualLength;
  52.     }
  53.